package de.nak.fireDepartment.administrationAction;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.struts.ActionSupport;

import de.nak.fireDepartment.actionForms.LoginForm;
import de.nak.fireDepartment.service.LoginService;

/**
 * Action that performs the logout-process
 * 
 * @author Sven Redelin
 */
public class LogoutAction extends ActionSupport {

	/**
	 * This deletes the current login
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return actionforward
	 * @throws Exception
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		WebApplicationContext ctx = getWebApplicationContext();
		LoginService loginService = (LoginService)ctx.getBean("loginService");
		// Perform Logout
		loginService.logoutUser();
		// ActionForm => LoginForm
		LoginForm loginForm = (LoginForm) form;
		// Clear the values in Form
		loginForm.setPassword("");
		loginForm.setUserName("");
		// Return result
		return mapping.findForward("success");
	}
}
